//
//  MySupplyOfGoodCess.m
//  XYMaterial
//
//  Created by 肖扬 on 16/1/12.
//  Copyright © 2016年 肖扬. All rights reserved.
//

#import "MySupplyOfGoodCess.h"
#import "homeModel.h"
@implementation MySupplyOfGoodCess
@synthesize titleLab,addressLab,priceLab,numberLab,button,stateImg,stateLab;
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SWIDTH, 10)];
        headView.backgroundColor = UIColorFromRGB(0xf3f2f2);
        [self addSubview:headView];
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 10, SWIDTH, 74)];
        bgView.backgroundColor = [UIColor whiteColor];
        [self addSubview:bgView];
        self.titleLab = [self createLabelFrame:CGRectMake(10, 10, SWIDTH - 20, 20) title:@"" titleColor:BLACKColor tag:0];
        titleLab.font = [UIFont systemFontOfSize:14];
        [bgView addSubview:titleLab];
        
//        NSString *address = [NSString stringWithFormat:@"地区：%@",self.supply.province_name];
//        int addressWidth = [address sizeWithFont:titleLab.font
//                               constrainedToSize:CGSizeMake(150, 30)
//                                   lineBreakMode:NSLineBreakByClipping].width;
        
        self.addressLab = [self createLabelFrame:CGRectMake(10, 35, (SWIDTH - 20), 12) title:@"" titleColor:GRAYColor tag:0];
        addressLab.font = [UIFont systemFontOfSize:12];
        [bgView addSubview:addressLab];

        self.numberLab = [self createLabelFrame:CGRectMake(SWIDTH/2 + 10, 35, SWIDTH/2-15, 12) title:@"" titleColor:GRAYColor tag:0];
        numberLab.font = [UIFont systemFontOfSize:12];
        [bgView addSubview:numberLab];

        self.priceLab = [self createLabelFrame:CGRectMake(10, 56, SWIDTH, 12) title:@"" titleColor:UIColorFromRGB(0xf94301) tag:0];
        priceLab.font = [UIFont systemFontOfSize:12];
        [bgView addSubview:priceLab];
        
        self.stateImg = [[UIImageView alloc]initWithFrame:CGRectMake(SWIDTH - 55, 63, 44, 16)];
        [self.stateImg setBackgroundColor:[UIColor clearColor]];
        [self addSubview:self.stateImg];
        
//        self.button = [self createButtonFrame:CGRectMake(SWIDTH - 55, 63, 44, 16) title:@"" viewController:self selector:nil tag:0];
//        self.button.titleLabel.font = [UIFont systemFontOfSize:12];
//        [self.button setBackgroundColor:[UIColor clearColor]];
//        [self.button setTitleColor:[UIColor whiteColor] forState:0];
//        [self addSubview:self.button];
        self.stateLab = [self createLabelFrame:CGRectMake(SWIDTH - 55, 63, 44, 16) title:@"" titleColor:WhiteColor tag:0];
        [self.stateLab setBackgroundColor:ClearColor];
        [self.stateLab setFont:[UIFont systemFontOfSize:12]];
        self.stateLab.textAlignment = NSTextAlignmentCenter;
        self.stateLab.highlighted = NO;
        [self addSubview:self.stateLab];
    }
    return self;
}
-(void)drawCellView:(NSMutableDictionary *)obj{
    self.titleLab.text = [obj objectForKey:@"brand_name"];
    NSString *procince = @"";
    NSString *city = @"";
    if ([obj objectForKey:@"province_name"]!=[NSNull null]) {
        procince =[obj objectForKey:@"province_name"];
    }
    if ([obj objectForKey:@"city_name"]!=[NSNull null]) {
        city = [obj objectForKey:@"city_name"];
    }
    NSString *address = [NSString stringWithFormat:@"地区:%@%@",procince,city];
    self.addressLab.text = address;
    NSString *number = [NSString stringWithFormat:@"数量：%@",[obj objectForKey:@"unit_number"]];
    self.numberLab.text = number;
    NSString *price = [NSString stringWithFormat:@"%@/%@",[obj objectForKey:@"price"],[obj objectForKey:@"unit"]];
    self.priceLab.text = price;
}
-(void)editLoadCellState:(BOOL)state{
    int x = 0;
    if (state) {
        x = 44;
    }
    [UIView animateWithDuration:0.2 animations:^{
        self.titleLab.frame = CGRectMake(10+x, 10, SWIDTH - 20, 20);
        self.addressLab.frame = CGRectMake(10+x, 35, (SWIDTH - 20), 12);
        self.numberLab.frame = CGRectMake(SWIDTH/2 + 10+x, 35, SWIDTH/2 - 15, 12);
        self.priceLab.frame = CGRectMake(10+x, 56, SWIDTH, 12);
    }];
}
-(void)drawHomeCellView:(homeModelSupply *)obj{
//    self.titleLab.text = obj.brand_name;
    if (![Unity isBlankString:obj.title]) {
        self.titleLab.text = obj.title;
    }else{
        NSString *title = @"";
        if (![Unity isBlankString:obj.brand_name]) {
            title = [title stringByAppendingString:[NSString stringWithFormat:@"%@",obj.brand_name]];
        }
        if (![Unity isBlankString:obj.material_name]) {
            title = [title stringByAppendingString:[NSString stringWithFormat:@" %@",obj.material_name]];
        }
        self.titleLab.text = title;
    }
    NSString *procince = @"";
    NSString *city = @"";
    if (![Unity isBlankString:obj.province_name]) {
        procince =obj.province_name;
    }else{
        procince = @"不限";
    }
    if (![Unity isBlankString:obj.city_name]) {
        city = obj.city_name;
    }else{
        city = @"";
    }
    NSString *str = [NSString stringWithFormat:@"地区:%@%@　数量:%@%@",procince,city,obj.unit_number,obj.unit];
//    NSString *address = [NSString stringWithFormat:@"地区:%@%@",procince,city];
    self.addressLab.text = str;
//    NSString *number = [NSString stringWithFormat:@"数量：%@",obj.unit_number];
//    self.numberLab.text = number;
    NSString *price = @"";
    if (![Unity isBlankString:obj.price]) {
        price = [NSString stringWithFormat:@"%@",obj.price];
        if (![Unity isBlankString:obj.unit]) {
            price = [NSString stringWithFormat:@"%@/%@",obj.price,obj.unit];
        }
    }
    if ([obj.audit_status integerValue]==0) {
        self.stateImg.image = [UIImage imageNamed:@"redImg"];
        self.stateImg.highlightedImage=[UIImage imageNamed:@"redImg"];
        self.stateLab.backgroundColor = REDColor;
        self.stateLab.text = @"审核中";
    }else if ([obj.audit_status integerValue]==1) {
        self.stateImg.image = [UIImage imageNamed:@"greenImg"];
        self.stateImg.highlightedImage=[UIImage imageNamed:@"greenImg"];
        self.stateLab.backgroundColor = GREENColor;
        self.stateLab.text = @"已审核";
    }else{
        self.stateImg.image = [UIImage imageNamed:@"grayImg"];
        self.stateImg.highlightedImage=[UIImage imageNamed:@"grayImg"];
        self.stateLab.backgroundColor = UIColorFromRGB(0xbfbfbf);
        self.stateLab.text = @"未通过";
    }
    
    self.priceLab.text = price;
}
//创建UILabel  tag值为三位数
- (UILabel *)createLabelFrame:(CGRect)frame
                        title:(NSString *)title
                   titleColor:(UIColor *)color
                          tag:(NSInteger)tag{
    UILabel *tempLabel = [[UILabel alloc]initWithFrame:frame];
    [tempLabel setBackgroundColor:[UIColor clearColor]];
    [tempLabel setText:title];
    [tempLabel setTag:tag];
    [tempLabel setTextColor:color];
    return tempLabel;
}
//创建UIButton tag值为四位数
- (UIButton *)createButtonFrame:(CGRect)frame
                          title:(NSString *)title
                 viewController:(id)viewController
                       selector:(SEL)selector
                            tag:(NSInteger)tag{
    UIButton *tempButton = [UIButton buttonWithType:0];
    [tempButton setFrame:frame];
    [tempButton setTag:tag];
    [tempButton setBackgroundColor:[UIColor clearColor]];
    [tempButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tempButton setTitle:title forState:UIControlStateNormal];
    [tempButton addTarget:viewController action:selector forControlEvents:UIControlEventTouchUpInside];
    return tempButton;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
